package protobuf;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import protobuf.analysis.ParseMap;
import protobuf.generate.cli2srv.login.Login;
import protobuf.generate.internal.Internal;
import protobuf.generate.srv2cli.push.Push;

import java.io.IOException;

public class ParseRegistryMap {

    static Logger logger= LoggerFactory.getLogger(ParseRegistryMap.class);


    //内部传输协议
    public static final int GTRANSFER = 900;
    public static final int GREET = 901;

    //与客户端相关的协议
    public static final int CLOGIN = 1000;
    public static final int SPUSH = 1001;
//    public static final int CREGISTER = 1001;
    public static final int SRESPONSE = 1002;



//    public static final int CPRIVATECHAT = 1003;
//    public static final int SPRIVATECHAT = 1004;


    //注册所有消息的解析器
    public static void initRegistry() throws IOException {

        logger.info("initRegistry");

        ParseMap.register(GTRANSFER, Internal.GTransfer::parseFrom, Internal.GTransfer.class); //内部传输协议用
        ParseMap.register(GREET, Internal.Greet::parseFrom, Internal.Greet.class); //内部服务器建立连接时的hello消息

        ParseMap.register(CLOGIN, Login.CLogin::parseFrom, Login.CLogin.class);
        //ParseMap.register(1001, Login.CRegister::parseFrom, Login.CRegister.class);
        ParseMap.register(SPUSH, Push.SPushMsg::parseFrom,Push.SPushMsg.class);
        ParseMap.register(SRESPONSE, Login.SResponse::parseFrom, Login.SResponse.class);
        //ParseMap.register(1003, Chat.CPrivateChat::parseFrom, Chat.CPrivateChat.class);
        //ParseMap.register(1004, Chat.SPrivateChat::parseFrom, Chat.SPrivateChat.class);
    }
}
